/****************************************************************
*  Name: Menu
*..Real Name: ux.megatron.gui.Menu
*  Race: megatron
*  Birth Date: 6-02-2008
****************************************************************/

jsx3.Class.defineClass(
    "ux.megatron.gui.Menu",
    ux.megatron.gui.Block,
    [jsx3.gui.Interactive],
    function(Menu, Menu_prototype) {
        Menu.TRIGGER_PERIOD = 300;
        Menu.allMenus = new Object();
        Menu.activeMenu = null;
        Menu.activeMenuBtn = null;
        Menu.overMenu = null;
        Menu.overItem = null;
        Menu.DEFAULT_BG = ux.megatron.Main.getServer().resolveURI("jsxaddin://user!cdbadmin/images/menu/menuButton.gif");
        Menu.ARROW = ux.megatron.Main.getServer().resolveURI("jsxaddin://user!Megatron/images/matrix/arrow.gif");
        Menu.DEFAULT_BG_COLOR = "#9b9bb7";
        Menu.OVER_BG = "";
        Menu.OVER_BG_COLOR = "";
        Menu.DOWN_BG = "";
        Menu.UP_BG = "";
        Menu.FONT_SIZE = "12px";
        Menu.ITEM_DEFAULT_BG = "";
        Menu.ITEM_DEFAULT_BG_COLOR = "#eeeeee";
        Menu.ITEM_OVER_BG = ux.megatron.Main.getServer().resolveURI("jsxaddin://user!cdbadmin/images/menu/itemBackground.gif");
        Menu.ITEM_OVER_BG_COLOR = "#fbfbb7";
        Menu.ITEM_DOWN_BG = "";
        Menu.ITEM_UP_BG = "";
        Menu.WIDTH = "67";
        Menu.HEIGHT = "24";
        Menu.TEXT = "";
        Menu.NAME = "menu";
        Menu.FONT_COLOR = "#424242";
        Menu.ITEM_OVER_FONT_COLOR = "#ffffff";
        Menu.ITEM_FONT_SIZE = "12px";
        Menu.ITEM_FONT_COLOR = "#474747";
        Menu.SHADOW_COLOR = "#999999";

        Menu.prototype.init = function(strName,vntLeft,vntTop,vntWidth,vntHeight,strHTML) {
            //Set menu button styles;
            /* @JSC :: begin DEBUG */
            Menu.log("Initialize.");
            /* @JSC :: end */
            this.defaultBg = this.defaultBg ? this.defaultBg : Menu.DEFAULT_BG;
            this.defaultBgColor = this.defaultBgColor ? this.defaultBgColor : Menu.DEFAULT_BG_COLOR;
            this.overBg = this.overBg ? this.overBg : Menu.OVER_BG;
            this.overBgColor = this.overBgColor ? this.overBgColor : Menu.OVER_BG_COLOR;
            this.downBg = this.downBg ? this.downBg : Menu.DOWN_BG;
            this.upBg = this.upBg ? this.upBg : Menu.UP_BG;
            this.jsxtext = this.jsxtext ? this.jsxtext : Menu.TEXT;
            this.jsxwidth = this.jsxwidth ? this.jsxwidth : Menu.WIDTH;
            this.jsxheight = this.jsxheight ? this.jsxheight : Menu.HEIGHT;
            this.jsxname = this.jsxname ? this.jsxname : Menu.NAME;
            this.fontColor = this.fontColor ? this.fontColor : Menu.FONT_COLOR;

            this.itemDefaultBg = this.itemDefaultBg ? this.itemDefaultBg : Menu.ITEM_DEFAULT_BG;
            this.itemDefaultBgColor = this.itemDefaultBgColor ? this.itemDefaultBgColor : Menu.ITEM_DEFAULT_BG_COLOR;
            this.itemOverBg = this.itemOverBg ? this.itemOverBg : Menu.ITEM_OVER_BG;
            this.itemOverBgColor = this.itemOverBgColor ? this.itemOverBgColor : Menu.ITEM_OVER_BG_COLOR;
            this.itemDownBg = this.itemDownBg ? this.itemDownBg : Menu.ITEM_DOWN_BG;
            this.itemUpBg = this.itemUpBg ? this.itemUpBg : Menu.ITEM_UP_BG;
            this.itemFontColor = this.itemFontColor ? this.itemFontColor : Menu.ITEM_FONT_COLOR;
            this.itemOverFontColor = this.itemOverFontColor ? this.itemOverFontColor : Menu.ITEM_OVER_FONT_COLOR;
            this.itemFontSize = this.itemFontSize ? this.itemFontSize : Menu.ITEM_FONT_SIZE;

            if(this.Pg){
                this.renderHandler = this.Pg;
            } else if(this.Di){
                this.renderHandler = this.Di;
            } else if(this.pi){
                this.renderHandler = this.pi;
            }

        };
        /*
        Menu.prototype.renderHandler = function(eventType, strMethod) {
            var eventHandler = "on" + eventType;
            var strEvent = "";
            var executeScript = "jsx3.log(this);jsx3.log(jsx3.html.getJSXParent(this));jsx3.html.getJSXParent(this).getDescendantsOfType('ux.megatron.gui.Menu')[0]." + strMethod + "(jsx3.gui.Event.wrap(event), this);";
            return " " + eventHandler + '="' + executeScript + '"';
        };
        */
        Menu.prototype.setXMLId = function(jsxxmlid){
            this.jsxxmlurl = null;
            this.jsxxmlid = jsxxmlid;
            if(Menu.objGUI)
                this.onAfterPaint(Menu.objGUI);
        };
        Menu.prototype.setXMLUrl = function(jsxxmlurl){
            this.jsxxmlid = null;
            this.jsxxmlurl = jsxxmlurl;
            if(Menu.objGUI)
                this.onAfterPaint(Menu.objGUI);
        };
        Menu.prototype.getCdfDoc = function(){
            var cdfDoc = null;
            if(this.jsxxmlid && (cdfDoc = this.getServer().getCache().getDocument(this.jsxxmlid))){
                /* @JSC :: begin DEBUG */
                Menu.log("Got data from xml cache.");
                /* @JSC :: end */
                return cdfDoc;
            } else if(this.jsxxmlurl){
                cdfDoc = jsx3.xml.CDF.Document.newDocument().loadXML(ux.megatron.Main.loadResource(this.jsxxmlurl, "ux.cdb.admin", "Menu_Static_Data", "xml"));
                /* @JSC :: begin DEBUG */
                jsx3.log(cdfDoc);
                /* @JSC :: end */
            } else if(this.jsxxml){
                cdfDoc = new jsx3.xml.CDF.Document.newDocument();
                /* @JSC :: begin DEBUG */
                Menu.log("Got data from xml string.");
                /* @JSC :: end */
            } else {
                /* @JSC :: begin DEBUG */
                Menu.log("No property data!");
                /* @JSC :: end */
                //alert("No property data!");
                return null;
            }
            return cdfDoc;
        };
        Menu.prototype.onAfterPaint = function(objGUI){
            Menu.objGUI = objGUI;
            //alert("onAfterPaint.");
            /* @JSC :: begin DEBUG */
            Menu.log("onAfterPaint.");
            /* @JSC :: end */
            this.init();
            var cdfDoc = this.getCdfDoc();
            this.cdfDoc = cdfDoc;
            if(cdfDoc){
                var i = cdfDoc.getChildIterator();
                var strHTML = "";
                while(i.hasNext()){
                    var record = i.next();
                    Menu.allMenus[record.getAttribute("jsxid")] = new Object();
                    Menu.allMenus[record.getAttribute("jsxid")].menuItemRecords = record.getChildIterator();
                    Menu.allMenus[record.getAttribute("jsxid")].menuItemCount = record.getChildNodes().size();
                    strHTML += this.showMenuButtons(record);
                }
                if(objGUI.parentNode)
                    objGUI.parentNode.innerHTML = strHTML;
            }
        };
        Menu.prototype.showMenuButtons = function(record){
            /* @JSC :: begin DEBUG */
            Menu.log("showMenuButtons, record is " + record);
            /* @JSC :: end */
            var me = this;
            var Event = jsx3.gui.Event;
            var strHTML = '<div jsxid="' + record.getAttribute("jsxid") + '" jsxname="menu_' + record.getAttribute("jsxid") + '" style="padding-top:1px;margin-right:5px; float:left; width:' + this.getWidth() + 'px;height:' + this.getHeight() + 'px;text-align:center;cursor:pointer;color:' + this.getFontColor() + ';font-size:' + this.getFontSize() + ';line-height:23px;" ' +
                this.renderHandler(Event.MOUSEOVER, "onMouseOver") +
                this.renderHandler(Event.CLICK, "onClick") +
                this.renderHandler(Event.MOUSEDOWN, "onMouseDown") +
                this.renderHandler(Event.MOUSEUP, "onMouseUp") +
                this.renderHandler(Event.MOUSEOUT, "onMouseOut") +
                '>' + record.getAttribute("jsxtext") +'</div>';
            return strHTML;
        };
        Menu.prototype.onMouseOver = function(objEvent, objGUI){
            /* @JSC :: begin DEBUG */
            Menu.log(objEvent);
            Menu.log(objGUI);
            /* @JSC :: end */
            var jsxid = objGUI.getAttribute("jsxid");
            /* @JSC :: begin DEBUG */
            Menu.log("MouseOver " + jsxid);
            /* @JSC :: end */
            var overItem = Menu._getItemGUI(objEvent, objGUI);
            overItem.style.background = "url('" + this.getDefaultBg() + "') no-repeat";
            overItem.style.color = this.getItemOverColor();
            if(Menu.activeMenuId){
                this.doHideMenu();
            }
            Menu.currentMenuGUI = objGUI;
            Menu.overMenuId = jsxid;
            if(Menu.allMenus[jsxid].menuItemCount){
                this.showMenu(objEvent, objGUI);
            } else {
                Menu.activeMenuId = jsxid;
            }
        };
        Menu.prototype.onClick = function(objEvent, objGUI){
            var jsxid = objGUI.getAttribute("jsxid");
            /* @JSC :: begin DEBUG */
            Menu.log("Click " + jsxid);
            /* @JSC :: end */
            if(Menu.allMenus[jsxid].menuItemCount == 0){
                this.onClickItem(objEvent, objGUI);
            }
        };
        Menu.prototype.onMouseDown = function(objEvent, objGUI){
            /* @JSC :: begin DEBUG */
            Menu.log("MouseDown " + objGUI.getAttribute("jsxid"));
            /* @JSC :: end */
        };
        Menu.prototype.onMouseUp = function(objEvent, objGUI){
            /* @JSC :: begin DEBUG */
            Menu.log("MouseUp " + objGUI.getAttribute("jsxid"));
            /* @JSC :: end */
        };
        Menu.prototype.onMouseOut = function(objEvent, objGUI){
            var jsxid = objGUI.getAttribute("jsxid");
            /* @JSC :: begin DEBUG */
            Menu.log("MouseOut " + jsxid);
            /* @JSC :: end */
            if(Menu.activeMenuId && (Menu.overMenuId == jsxid)){
                Menu.overMenuId = null;
                this.hideMenu();
            }
        };
        Menu.prototype.hideMenu = function(objEvent, objGUI) {
            /* @JSC :: begin DEBUG */
            Menu.log("Menu will be hide.");
            /* @JSC :: end */
            if(this.t){
                clearTimeout(this.t);
            }
            var me = this;
            this.t = setTimeout(function(){
                if(Menu.activeMenuId && !Menu.overItemId && !Menu.overMenuId){
                    me.doHideMenu();
                } else {
                    /* @JSC :: begin DEBUG */
                    Menu.log("Cancel hide menu.");
                    /* @JSC :: end */
                }
            }, Menu.TRIGGER_PERIOD);

        };
        Menu.prototype.doHideSubMenu = function() {
            if(this.activeSubMenuId){
                Menu.allMenus[this.activeSubMenuId].menuItems.hide();
                Menu.allMenus[this.activeSubMenuId].menuItemsShadow.hide();
                this.activeSubMenuId = null;
            }
        };
        Menu.prototype.doHideMenu = function(){
            this.doHideSubMenu();
            if(Menu.allMenus[Menu.activeMenuId].menuItemCount){
                Menu.allMenus[Menu.activeMenuId].menuItems.hide();
                Menu.allMenus[Menu.activeMenuId].menuItemsShadow.hide();
            }
            Menu.activeMenuId = null;
            Menu.overItemId = null;
            if(Menu.currentMenuGUI) {
                Menu.currentMenuGUI.style.background = "";
                Menu.currentMenuGUI.style.color = this.getFontColor();
            }
            /* @JSC :: begin DEBUG */
            Menu.log("Menu hide.");
            /* @JSC :: end */
        };
        Menu.prototype.showSubMenu = function(objEvent, objGUI) {
            var jsxid = objGUI.getAttribute("jsxid");
            this.activeSubMenuId = jsxid;
            /* @JSC :: begin DEBUG */
            Menu.log("ShowSubMenu " + jsxid);
            /* @JSC :: end */
            if(Menu.allMenus[jsxid].menuItems){
                var objHW = Menu.allMenus[jsxid].menuItems;
                /* @JSC :: begin DEBUG */
                Menu.log("Load menu " + jsxid + " from cache.");
                /* @JSC :: end */
            } else {
                /* @JSC :: begin DEBUG */
                Menu.log("Generate html of menu " + jsxid);
                /* @JSC :: end */
                var Event = jsx3.gui.Event;
                var topDivHtml = '<div style="display:block;"><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 5px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 3px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 2px;"></div><div style="display:block;height:2px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 1px;"></div></div>';
                var bottomDivHtml = '<div style="display:block;"><div style="display:block;height:2px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 1px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 2px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 3px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 5px;"></div></div>';
                var strHTML = '<div tabindex="0" jsxindex="0">' +
                    topDivHtml +
                    '<div ' +
                    this.renderHandler(Event.MOUSEOVER, "onMouseOverSubItem") +
                    this.renderHandler(Event.CLICK, "onClickItem") +
                    this.renderHandler(Event.MOUSEOUT, "onMouseOutSubItem") +
                    'style="width:auto!important;width:0;cursor:pointer; color:' + this.getItemFontColor() + ';font-size:' + this.itemFontSize + ';background-color:' + this.getItemDefaultBgColor() + ';"' +
                    '>' +
                    this.getContent(jsxid) +
                    '</div>' +
                    bottomDivHtml +
                    '</div>';
                var objHW = new jsx3.gui.Heavyweight(null, this);
                objHW.setHTML(strHTML);
                objHW.addXRule(objGUI,"E","W",0);
                objHW.addYRule(objGUI,"N","N",-4);
                objHW.setZIndex(100);
                Menu.allMenus[jsxid].menuItems = objHW;
                /* @JSC :: begin DEBUG */
                Menu.log("Menu " + jsxid + " is cached.");
                /* @JSC :: end */
            }
            objHW.show();
            var hwGUI = objHW.getRendered();
            var divContent = hwGUI.childNodes[0].childNodes[1];
            var contentWidth = Math.max(divContent.offsetWidth - 2, divContent.clientWidth);
            hwGUI.childNodes[0].childNodes[0].style.width = contentWidth;
            hwGUI.childNodes[0].childNodes[2].style.width = contentWidth;
            if(jsx3.CLASS_LOADER.IE){
                for(var i = 0; i < hwGUI.childNodes[0].childNodes[1].childNodes.length; i ++){
                    hwGUI.childNodes[0].childNodes[1].childNodes[i].style.width = contentWidth;
                }
            }
            var shadowHW = new jsx3.gui.Heavyweight(null, this);
            shadowHW.setHTML("<div tabindex=\"0\" jsxindex=\"0\" style=\"filter:Alpha(opacity=50);-moz-opacity:0.5;opacity:0.5;\"><div style=\"display:block;\"><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 5px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 3px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 2px;\"></div><div style=\"display:block;height:2px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 1px;\"></div></div><div style=\"background-color:" + this.getShadowColor() + ";\">&nbsp;</div><div style=\"display:block;\"><div style=\"display:block;height:2px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 1px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 2px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 3px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 5px;\"></div></div></div>");
            shadowHW.addXRule(hwGUI, "W", "W", 2);
            shadowHW.addYRule(hwGUI, "N", "N", 2);
            shadowHW.setZIndex(99);
            shadowHW.show();
            if(Menu.allMenus[jsxid].menuItemsShadow)Menu.allMenus[jsxid].menuItemsShadow.destroy();
            Menu.allMenus[jsxid].menuItemsShadow = shadowHW;
            shadowGUI = shadowHW.getRendered();
            shadowGUI.childNodes[0].childNodes[0].style.width = contentWidth;
            shadowGUI.childNodes[0].childNodes[1].style.width = contentWidth;
            shadowGUI.childNodes[0].childNodes[2].style.width = contentWidth;
            shadowGUI.childNodes[0].childNodes[1].style.height = divContent.offsetHeight;
        };
        Menu.prototype.onMouseOverSubItem = function(objEvent, objGUI) {
            var overItem = Menu._getItemGUI(objEvent, objGUI);
            var jsxid = overItem.getAttribute("jsxid");
            /* @JSC :: begin DEBUG */
            Menu.log("MouseOverSubItem " + jsxid);
            /* @JSC :: end */
            overItem.style.background = "url('" + this.getItemOverBg() + "') repeat-x";
            overItem.style.color = this.getItemOverColor();
            Menu.overItemId = jsxid;
            if(Menu.allMenus[jsxid] && Menu.allMenus[jsxid].menuItemCount){
                this.showSubMenu(objEvent, overItem);
            } else {
            }
        };
        Menu.prototype.onMouseOutSubItem = function(objEvent, objGUI) {
            var overItem = Menu._getItemGUI(objEvent, objGUI);
            var jsxid = overItem.getAttribute("jsxid");
            /* @JSC :: begin DEBUG */
            Menu.log("MouseOutSubItem " + jsxid);
            /* @JSC :: end */
            overItem.style.background = "";
            overItem.style.color = this.getItemFontColor();
            if(Menu.activeMenuId && (Menu.overItemId == jsxid)){
                Menu.overItemId = null;
                this.hideMenu();
            }
        };
        Menu.prototype.showMenu = function(objEvent, objGUI) {
            var jsxid = objGUI.getAttribute("jsxid");
            /* @JSC :: begin DEBUG */
            Menu.log("ShowMenu " + jsxid);
            /* @JSC :: end */
            if(Menu.allMenus[jsxid].menuItems){
                var objHW = Menu.allMenus[jsxid].menuItems;
                /* @JSC :: begin DEBUG */
                Menu.log("Load menu " + jsxid + " from cache.");
                /* @JSC :: end */
            } else {
                /* @JSC :: begin DEBUG */
                Menu.log("Generate html of menu " + jsxid);
                /* @JSC :: end */
                var Event = jsx3.gui.Event;
                var topDivHtml = '<div style="display:block;"><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 5px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 3px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 2px;"></div><div style="display:block;height:2px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 1px;"></div></div>';
                var bottomDivHtml = '<div style="display:block;"><div style="display:block;height:2px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 1px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 2px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 3px;"></div><div style="display:block;height:1px;overflow:hidden;background:' + this.getItemDefaultBgColor() + ';margin:0 5px;"></div></div>';
                var strHTML = '<div tabindex="0" jsxindex="0">' +
                    topDivHtml +
                    '<div ' +
                    this.renderHandler(Event.MOUSEOVER, "onMouseOverItem") +
                    this.renderHandler(Event.CLICK, "onClickItem") +
                    this.renderHandler(Event.MOUSEDOWN, "onMouseDownItem") +
                    this.renderHandler(Event.MOUSEUP, "onMouseUpItem") +
                    this.renderHandler(Event.MOUSEOUT, "onMouseOutItem") +
                    'style="width:auto!important;width:0;cursor:pointer; color:' + this.getItemFontColor() + ';font-size:' + this.itemFontSize + ';background-color:' + this.getItemDefaultBgColor() + ';"' +
                    '>' +
                    this.getContent(jsxid) +
                    '</div>' +
                    bottomDivHtml +
                    '</div>';
                var objHW = new jsx3.gui.Heavyweight(null, this);
                objHW.setHTML(strHTML);
                objHW.addXRule(objGUI,"W","W",0);
                objHW.addYRule(objGUI,"S","N",3);
                objHW.setZIndex(100);
                Menu.allMenus[jsxid].menuItems = objHW;
                /* @JSC :: begin DEBUG */
                Menu.log("Menu " + jsxid + " is cached.");
                /* @JSC :: end */
            }
            objHW.show();
            var hwGUI = objHW.getRendered();
            var divContent = hwGUI.childNodes[0].childNodes[1];
            var contentWidth = Math.max(divContent.offsetWidth - 2, divContent.clientWidth);
            hwGUI.childNodes[0].childNodes[0].style.width = contentWidth;
            hwGUI.childNodes[0].childNodes[2].style.width = contentWidth;
            if(jsx3.CLASS_LOADER.IE){
                for(var i = 0; i < hwGUI.childNodes[0].childNodes[1].childNodes.length; i ++){
                    hwGUI.childNodes[0].childNodes[1].childNodes[i].style.width = contentWidth;
                }
            }
            var shadowHW = new jsx3.gui.Heavyweight(null, this);
            shadowHW.setHTML("<div tabindex=\"0\" jsxindex=\"0\" style=\"filter:Alpha(opacity=50);-moz-opacity:0.5;opacity:0.5;\"><div style=\"display:block;\"><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 5px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 3px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 2px;\"></div><div style=\"display:block;height:2px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 1px;\"></div></div><div style=\"font-size:1px;background-color:" + this.getShadowColor() + ";\">&nbsp;</div><div style=\"display:block;\"><div style=\"display:block;height:2px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 1px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 2px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 3px;\"></div><div style=\"display:block;height:1px;overflow:hidden;background:" + this.getShadowColor() + ";margin:0 5px;\"></div></div></div>");
            shadowHW.addXRule(hwGUI, "W", "W", 2);
            shadowHW.addYRule(hwGUI, "N", "N", 2);
            shadowHW.setZIndex(99);
            shadowHW.show();
            if(Menu.allMenus[jsxid].menuItemsShadow)Menu.allMenus[jsxid].menuItemsShadow.destroy();
            Menu.allMenus[jsxid].menuItemsShadow = shadowHW;
            shadowGUI = shadowHW.getRendered();
            shadowGUI.childNodes[0].childNodes[0].style.width = contentWidth;
            shadowGUI.childNodes[0].childNodes[1].style.width = contentWidth;
            shadowGUI.childNodes[0].childNodes[2].style.width = contentWidth;
            shadowGUI.childNodes[0].childNodes[1].style.height = divContent.offsetHeight;
            Menu.activeMenuId = jsxid;
        };
        Menu.prototype.onMouseOverItem = function(objEvent, objGUI) {
            this.doHideSubMenu();
            var overItem = Menu._getItemGUI(objEvent, objGUI);
            if(overItem.getAttribute("name") == "arrow"){
                overItem = overItem.parentNode;
            }
            var jsxid = overItem.getAttribute("jsxid");
            /* @JSC :: begin DEBUG */
            Menu.log("MouseOverItem " + jsxid);
            /* @JSC :: end */
            overItem.style.background = "url('" + this.getItemOverBg() + "') repeat-x";
            overItem.style.color = this.getItemOverColor();
            Menu.overItemId = jsxid;

            if(Menu.allMenus[jsxid] && Menu.allMenus[jsxid].menuItemCount){
                this.showSubMenu(objEvent, overItem);
            } else {
            }
        };
        Menu._getItemGUI = function(objEvent, objGUI) {
            var itemGUI = objEvent.srcElement();
            return itemGUI;
        };
        Menu.prototype.onClickItem = function(objEvent, objGUI) {
            /* @JSC :: begin DEBUG */
            Menu.log("ClickItem " + objGUI.getAttribute("jsxid"));
            /* @JSC :: end */
            if(Menu.activeMenuId)this.doHideMenu();
            objEvent.cancelBubble();
            var itemGUI = Menu._getItemGUI(objEvent, objGUI);
            this._executeRecord(objEvent, itemGUI.getAttribute("jsxid"));
        };
        Menu_prototype._executeRecord = function(objEvent, strRecordId) {
              var myScript = this.getAttribute("jsxexecute");
              var context = {strRECORDID:strRecordId};
              context.objEVENT = objEvent;
              bContinue = jsx3.util.strEmpty(myScript) ? true : this.eval(myScript, context);
              if (bContinue !== false && objEvent)
                  this.doEvent(jsx3.gui.Interactive.EXECUTE, context);
        };
        Menu.prototype.onMouseDownItem = function(objEvent, objGUI) {
            var overItem = Menu._getItemGUI(objEvent, objGUI);
            /* @JSC :: begin DEBUG */
            Menu.log("MouseDownItem " + overItem.getAttribute("jsxid"));
            /* @JSC :: end */
        };
        Menu.prototype.onMouseUpItem = function(objEvent, objGUI) {
            var overItem = Menu._getItemGUI(objEvent, objGUI);
            /* @JSC :: begin DEBUG */
            Menu.log("MouseUpItem " + overItem.getAttribute("jsxid"));
            /* @JSC :: end */
        };
        Menu.prototype.onMouseOutItem = function(objEvent, objGUI) {
            var overItem = Menu._getItemGUI(objEvent, objGUI);
            var jsxid = overItem.getAttribute("jsxid");
            /* @JSC :: begin DEBUG */
            Menu.log("MouseOutItem " + jsxid);
            /* @JSC :: end */
            overItem.style.background = "";
            //overItem.style.backgroundColor = this.getItemDefaultBgColor();
            overItem.style.color = this.getItemFontColor();
            if(Menu.activeMenuId && (Menu.overItemId == jsxid)){
                Menu.overItemId = null;
                this.hideMenu();
            }
        };
        Menu.prototype.getShadowColor = function() {
            return Menu.SHADOW_COLOR;
        };
        Menu.prototype.getItemFontColor = function() {
            return Menu.ITEM_FONT_COLOR;
        };
        Menu.prototype.getItemOverColor = function() {
            return Menu.ITEM_OVER_FONT_COLOR;
        };
        Menu.prototype.getItemDefaultBgColor = function() {
            return Menu.ITEM_DEFAULT_BG_COLOR;
        };
        Menu.prototype.getItemOverBg = function() {
            return Menu.ITEM_OVER_BG;
        };
        Menu.prototype.getDefaultBg = function() {
            return Menu.DEFAULT_BG;
        };
        Menu.prototype.getFontColor = function() {
            return Menu.FONT_COLOR;
        };
        Menu.prototype.getWidth = function() {
            return Menu.WIDTH;
        };
        Menu.prototype.getHeight = function() {
            return Menu.HEIGHT;
        };
        Menu.prototype.getFontSize = function() {
            return Menu.FONT_SIZE;
        };
        Menu.prototype.getContent = function(jsxid) {
            /* @JSC :: begin DEBUG */
            Menu.log("Get Menu Items of " + jsxid);
            /* @JSC :: end */
            var strHTML = "";
            var i = Menu.allMenus[jsxid].menuItemRecords;
            while(i.hasNext()){
                var record = i.next();
                strHTML += '<div nowrap style="padding:2px 10px;"jsxid="' + record.getAttribute("jsxid") + '">' + record.getAttribute("jsxtext");
                if((!Menu.allMenus[record.getAttribute("jsxid")]) && (record.getChildNodes().size() > 0)){
                    strHTML += '&nbsp;&nbsp;<img width="10" height="10" name="arrow" src="' + Menu.ARROW + '" border="0" onmouseover="return false;">';
                    Menu.allMenus[record.getAttribute("jsxid")] = new Object();
                    Menu.allMenus[record.getAttribute("jsxid")].menuItemRecords = record.getChildIterator();
                    Menu.allMenus[record.getAttribute("jsxid")].menuItemCount = record.getChildNodes().size();
                }
                strHTML += "</div>";
            }
            return strHTML;
        };
        Menu.log = function(log) {
            /* @JSC :: begin DEBUG */
            jsx3.log("ux.megatron.gui.Menu: " + log);
            /* @JSC :: end */
        };
    });